package entities;

import java.awt.Image;

import javax.swing.ImageIcon;

import constants.BonusType;

import logic.Utilities;

/** The Bonus's class for the brick breaker game.
 * @author Team 1
 *
 */
@SuppressWarnings("serial")
public class Bonus extends MovableEntity {

	private ImageIcon icon;		//The ImageIcon of the label.
	private BonusType type;		//the bonus type.
	
	/** The bonus's constructor without initial movement.
	 * @param x : the entity's upper-left corner's x coordinate.
	 * @param y : the entity's upper-left corner's y coordinate.
	 * @param type : the bonus type.
	 * @param xScale : the x resize scale. If it's lower than one it reduces the images original width, increase it otherwise.
	 * @param yScale : the y resize scale. If it's lower than one it reduces the images original height, increase it otherwise.
	 */
	public Bonus(int x, int y, BonusType type, float xScale, float yScale) {
		super(x, y);
		this.type = type;
		Image image = Utilities.loadImage("res/"+ type.toString() +"Bonus.png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/" + type.toString() + "Bonus.png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x, (int)this.y, this.width, this.height);
	}

	/** The bonus's constructor with initial movement.
	 * @param x : the entity's upper-left corner's x coordinate.
	 * @param y : the entity's upper-left corner's y coordinate.
	 * @param dx : the horizontal speed.
	 * @param dy : the vertical speed. 
	 * @param type : the bonus type.
	 * @param xScale : the x resize scale. If it's lower than one it reduces the images original width, increase it otherwise.
	 * @param yScale : the y resize scale. If it's lower than one it reduces the images original height, increase it otherwise.
	 */
	public Bonus(int x, int y, int dx, int dy, BonusType type, float xScale, float yScale) {
		super(x, y, dx, dy);
		this.type = type;
		Image image = Utilities.loadImage("res/"+ type.toString() +"Bonus.png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/" + type.toString() + "Bonus.png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x, (int)this.y, this.width, this.height);
	}
	
	public void resize(float xScale, float yScale) {
		super.resize(xScale, yScale);
		this.icon = new ImageIcon(Utilities.resizeImage(xScale, yScale, "res/" + type.toString() + "Bonus.png"));
		this.setIcon(icon);
	}
	
	/** Returns the type of the bonus.
	 * @return type.
	 */
	public BonusType getType() {
		return type;
	}
	

	/** Return the bonus's width for all resolution giving the windows width divided by 1280.
	 * @param xScale : The windows horizontal proportion value.
	 * @return The value of the ball's width depending on the horizontal scale.
	 */
	public static int getWidth(float xScale) {
		return Math.round(27 * xScale);
	}
	
	/**Return the bonus's height for all resolution giving the windows height divided by 720.
	 * @param yScale : The windows vertical proportion value.
	 * @return The value of the ball's height depending on the vertical scale.
	 */
	public static int getHeight(float yScale) {
		return Math.round(16 * yScale);
	}
}
